package com.motong.gongdan.service;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.motong.gongdan.entity.FormTableDetail;
import com.motong.gongdan.mapper.FormTableDetailMapper;
import com.motong.gongdan.mapper.WorkReportMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;

/**
 * @author lsw
 * @time 2022/5/26 11:32
 */
@Service
public class FormTableDetailService extends ServiceImpl<FormTableDetailMapper, FormTableDetail> {


    @Resource
    private WorkReportMapper workReportMapper;

    /**
     * 根据工单编码分组获取良品数
     *
     * @param workCodes 工单编码集合
     */
    public Map<String, BigDecimal> goodNumGroupByWorkCodes(Set<String> workCodes) {
        List<Map<String, Object>> data = workReportMapper.goodNumGroupByWorkCodes(workCodes);
        Map<String, BigDecimal> workCodeNumMap = new HashMap<>();
        if (Objects.nonNull(data) && !data.isEmpty()) {
            data.forEach(i->workCodeNumMap.put(i.get("workOrderCode").toString(), Convert.toBigDecimal(i.get("goodProductNumber"))));
        }
        return workCodeNumMap;
    }
}
